package com.wx.oss.adapter;

import com.wx.oss.entity.FileInfo;
import com.wx.oss.util.MinioUtil;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;

/**
 * @BelongsProject: xx-club
 * @BelongsPackage: com.wx.oss.adapter
 * @Author: wangx
 * @CreateTime: 2024-03-18  14:29
 * @Description:
 * @Version: 1.0
 */

public class MinioStorageAdapter  implements StorageAdapter{
    @Resource
    private MinioUtil minioUtil;

    /**
     * minioUrl
     */
    @Value("${minio.url}")
    private String url;
    @Override
    @SneakyThrows
    public void makeBucket(String bucketName) {
        minioUtil.makeBucket(bucketName);
    }

    @Override
    @SneakyThrows
    public List<String> listBuckets() {
        return minioUtil.listBuckets();
    }

    @Override
    @SneakyThrows
    public List<FileInfo> getAllFile(String bucketName) {
        return minioUtil.getAllFile(bucketName);
    }

    @Override
    @SneakyThrows
    public void removeBucket(String bucketName) {
        minioUtil.removeBucket(bucketName);
    }

    @Override
    public void uploadFile(MultipartFile multipartFile, String bucketName, String fileName) {

    }

    @Override
    @SneakyThrows
    public InputStream downloadFile(String bucketName, String fileName) {
        return minioUtil.downloadFile(bucketName, fileName);
    }

    @Override
    @SneakyThrows
    public void removeFile(String bucketName, String fileName) {
            minioUtil.removeFile(bucketName, fileName);
    }

    @Override
    public String getFileUrl(String bucketName, String fileName) {
        return url + "/" + bucketName + "/" + fileName;
    }
}


